import { ADMIN_PREFIX } from 'src/modules/admin/admin.constants';
import { ApiResponse, ApiSecurity, ApiTags, ApiOperation } from '@nestjs/swagger';
import { Body, Controller, Get, Post, Query } from '@nestjs/common';

import SysTag from '@/entities/admin/sys-tags.entity';
import { SysTagService } from './tag.service';
import { CreateTagDto, UpdateArticleTagDto, DeleteTagDto, ListTagDto } from './tag.dto';

@ApiSecurity(ADMIN_PREFIX)
@ApiTags('标签模块')
@Controller('tag')
export class SysTagController {
  constructor(private tagService: SysTagService) {}

  /**
   * 添加标签
   * @param tag
   */
  @ApiOperation({
    summary: '创建标签',
  })
  @ApiResponse({ status: 200, description: '创建标签', type: [SysTag] })
  @Post('create')
  create(@Body() tag: CreateTagDto) {
    return this.tagService.create(tag);
  }

  /**
   * 获取所有标签
   */
  @ApiOperation({
    summary: '获取所有标签',
  })
  @ApiResponse({ status: 200, description: 'list' })
  @Get('list')
  findAll(@Query() queryParams: ListTagDto): Promise<SysTag[]> {
    return this.tagService.findAll(queryParams);
  }

  /**
   * 获取指定标签
   * @param id
   */
  @ApiOperation({
    summary: '获取指定标签',
  })
  @ApiResponse({ status: 200, description: 'info' })
  @Get('info')
  findById(@Query('id') id) {
    return this.tagService.findById(id);
  }

  /**
   * 获取指定标签，包含相关文章信息
   * @param id
   */
  @ApiOperation({
    summary: '获取指定标签，包含相关文章信息',
  })
  @ApiResponse({ status: 200, description: 'tag/article' })
  @Get('tag/article')
  getArticleById(@Query('id') id) {
    return this.tagService.getArticleById(id);
  }

  /**
   * 更新标签
   * @param id
   * @param tag
   */
  @ApiOperation({
    summary: '更新标签',
  })
  @ApiResponse({ status: 200, description: 'update' })
  @Post('update')
  updateById(@Body() dto: UpdateArticleTagDto) {
    return this.tagService.updateById(dto);
  }

  /**
   * 删除标签
   * @param id
   */
  @ApiOperation({
    summary: '删除标签',
  })
  @ApiResponse({ status: 200, description: 'delete' })
  @Post('delete')
  deleteById(@Query() dto: DeleteTagDto) {
    return this.tagService.deleteById(dto.id);
  }
}
